home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / pxewin.zip / BROWSER.HPP < prev    next >
C/C++ Source or Header  |  1992-01-17  |  10KB  |  335 lines

  1. // BROWSER.HPP //
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //    This header contains the following items:
  6. //
  7. //    1.  Class PXListBox.  Redefines listboxes for browsing PDOX tables.
  8. //
  9. //    2.  Stucture LB_PARM.  Stores the parameters for all the list boxes.
  10. //
  11. //    3.  Class DBDISPLAY.  Displays the database in page format with 20
  12. //    records per page.
  13. //
  14. //    4.  Class PXScroller.  Redifines the scroller for scrolling PDOX
  15. //    tables.  The vertical scroll is all that is redefined.
  16. //
  17. //    5.  Class Browser.  Creates a browser window that is MDI complient.
  18. //
  19. //    6.  Class BrowserFrame.  Creates a MDI frame for creating browser
  20. //    windows.
  21. //
  22. // Description
  23. //
  24. //    This header contains all the interfaces classes and structures to
  25. //    construct MDI complient browser windows for Windows application
  26. //    interface of PDOX tables.
  27. //
  28. // End ---------------------------------------------------------------------
  29.  
  30. // External Reference Name for this Header ---------------------------------
  31.  
  32. #ifndef BROWSER_HPP
  33.     #define BROWSER_HPP
  34.  
  35. // End ---------------------------------------------------------------------
  36.  
  37. // Interface Dependendies --------------------------------------------------
  38.  
  39. #ifndef __STRING_H
  40.     #include <string.h>
  41. #endif
  42. #ifndef __STDIO_H
  43.     #include <stdio.h>
  44. #endif
  45. #ifndef __OWL_H
  46.     #include <owl.h>
  47. #endif
  48. #ifndef __FILEDIAL_H
  49.     #include <filedial.h>
  50. #endif
  51. #ifndef __MDI_H
  52.     #include <mdi.h>
  53. #endif
  54. #ifndef __LISTBOX_H
  55.     #include <listbox.h>
  56. #endif
  57. #ifndef __STATIC_H
  58.     #include <static.h>
  59. #endif
  60. #ifndef PXSTRUCT_CPP
  61.     #include "pxstruct.cpp"
  62. #endif
  63.  
  64. // End ---------------------------------------------------------------------
  65.  
  66. #define PAGE_SIZE 20                /* The number of records in
  67.                            a page */
  68.  
  69. #define WM_CHKCHILD 0x400            /* To send a message to the
  70.                            BrowserFrame when a
  71.                            child is destroyed */
  72.  
  73. #define WM_SETWTCUR 0x410            /* Cursor wait message */
  74. #define WM_SETNMCUR 0x420            /* Cursor normal message */
  75.  
  76.  
  77. // structure LB_PARM //
  78.  
  79. class PXListBox;
  80. class Browser;
  81.  
  82. typedef struct LB_PARM{
  83.     PXField *my_field;            /* Points to the field
  84.                            cooresponding to this
  85.                            list box */
  86.     int x;                    /* X coordinates of origin
  87.                            point of list box */
  88.     int w;                    /* Width of list box */
  89.     PXListBox *my_box;            /* Points to the list box
  90.                            object */
  91.     TStatic *my_header;            /* Points to field header
  92.                            static text block object
  93.                         */
  94. }LB_PARM;
  95.  
  96. // Description -------------------------------------------------------------
  97. //
  98. //    This structure is used to define the parameters necessary to
  99. //    construct and use a list box for each field in the database.
  100. //
  101. // End ---------------------------------------------------------------------
  102.  
  103. // class DBDISPLAY //
  104.  
  105. #define CHAR_WIDTH 8                /* This is the size of a
  106.                            character */
  107. class DBDISPLAY:public PXDIS
  108. {
  109. protected:
  110.     LB_PARM **my_parm;                      /* Define an array of
  111.                            pointers for the fields
  112.                            parameter set */
  113.     int sum;                /* sum is the total number of
  114.                            characters it takes to
  115.                            display all the fields.
  116.                            This will be used to set
  117.                            the scroll bar range. */
  118.     RECORDNUMBER top_rec;            /* Top record number */
  119.     int item;                /* List box item number */
  120.     int UpdateFlag;                /* Update display if set */
  121.     PTWindowsObject AP;            /* Copy of parent object */
  122. public:
  123.     DBDISPLAY();
  124.     int RetSum()                /* Returns the total number
  125.                            of characters in all
  126.                            fields */
  127.     {
  128.         return sum;
  129.     }
  130.     virtual ~DBDISPLAY();
  131.     int SetUp(Browser *AParent);    /* Set up database display */
  132.     void SelRecord(int item);        /* Selects the record at a
  133.                            certain list box item
  134.                            number */
  135.     void FillBoxes(RECORDNUMBER rec);    /* Fills list boxes with
  136.                            data */
  137.     void ScrollUp();            /* Scrolls the page up by one
  138.                            record */
  139.     void ScrollDwn();            /* Scrolls the page down by
  140.                            one record */
  141.     void IncRec();                /* Increments by one record
  142.                         */
  143.     void DecRec();                /* Decrements by one record
  144.                         */
  145.     RECORDNUMBER RetCurRec()        /* Return current record */
  146.     {
  147.         return top_rec + item;
  148.     }
  149.     int RetFlag()                /* Returns status of update
  150.                            flag to test if display
  151.                            should be updated or not
  152.                         */
  153.     {
  154.         return UpdateFlag;
  155.     }
  156.  
  157. };
  158.  
  159. // Description -------------------------------------------------------------
  160. //
  161. //    This class contains all the members necessary to initialize, browse
  162. //    and edit the database.
  163. //
  164. // End ---------------------------------------------------------------------
  165.  
  166. // class Browser //
  167.  
  168. class Browser:public TWindow
  169. {
  170. private:
  171.     int flag;                /* Existance flag for window
  172.                            bailout */
  173. public:
  174.     DBDISPLAY *my_display;            /* My database display
  175.                            object */
  176.     char *name;                /* Name of database file */
  177.  
  178.     Browser(PTWindowsObject AParent,int ChildNum);
  179.     virtual ~Browser();
  180.     virtual void SetupWindow();
  181.     int RetFlag()                /* Return existance flag */
  182.     {
  183.         return flag;
  184.     }
  185. };
  186.  
  187. // Description -------------------------------------------------------------
  188. //
  189. //    This class will be used for each browser window you wish to use.
  190. //
  191. // End ---------------------------------------------------------------------
  192.  
  193. // class PXListBox //
  194.  
  195. class PXListBox:public TListBox
  196. {
  197. private:
  198.     DBDISPLAY *my_display;            /* Display object pointer */
  199. public:
  200.     PXListBox(Browser *AParent,
  201.         int AnId,int X,int Y,int W,int H,
  202.         PTModule AModule = NULL);
  203.     virtual void LBNSelChange(RTMessage Msg) =
  204.         [NF_FIRST + LBN_SELCHANGE];
  205.  
  206.     // Redefine WMPaint so that list boxes are not drawn when the
  207.     // the Update flag is reset.  Since the OWL will do screen refresh
  208.     // on the list boxes for each new entrie in the box, it is better
  209.     // to do a paint after the list has completely been updated.
  210.  
  211.     virtual void WMPaint(RTMessage Msg) = [WM_FIRST + WM_PAINT];
  212. };
  213.  
  214. // Description -------------------------------------------------------------
  215. //
  216. //    The PXListBox class is a modification of the TListBox class.  A
  217. //    pointer to the DBDISPLAY object is passed.  This object is used
  218. //    to call the SelRecord function.  If a selection event occurs in
  219. //    any of the list boxes, the list box calls the SelRecord function
  220. //    that selects all the other fields so that the record bar changes
  221. //    to coorespond to that item.  The focus remains set at the item
  222. //    you have selected.
  223. //
  224. // End ---------------------------------------------------------------------
  225.  
  226. // class PXScroller //
  227.  
  228. class PXScroller:public TScroller
  229. {
  230. private:
  231.     DBDISPLAY *my_display;            /* Copy of database display
  232.                            routine */
  233. public:
  234.     PXScroller(Browser *TheWindow,
  235.         int TheXUnit,int TheYUnit,long TheXRange,long TheYRange):
  236.         TScroller((PTWindow)TheWindow,TheXUnit,TheYUnit,
  237.         TheXRange,TheYRange)
  238.     {
  239.         my_display = TheWindow->my_display;
  240.     }
  241.     virtual void VScroll(WORD ScrollEvent,    /* Redefine vert. scroll */
  242.     int ThumbPos);
  243. };
  244.  
  245. // Description -------------------------------------------------------------
  246. //
  247. //    This class customizes the scroller for operation with the database.
  248. //    The horizontal scroller is OK but the vertical scroller needs to
  249. //    be modified so that only the data scrolls and not the whole window.
  250. //
  251. // End ---------------------------------------------------------------------
  252.  
  253. // function CountChild //
  254.  
  255. void CountChild(void *,void *CountPtr)
  256. {
  257.     ++*(int *)CountPtr;
  258. }
  259.  
  260. // Summary -----------------------------------------------------------------
  261. //
  262. //    This function keeps track of the number of child windows you have
  263. //    opened.
  264. //
  265. // Parameters
  266. //
  267. //    I don't understand how this function works.
  268. //
  269. // Return Value
  270. //
  271. //    None.
  272. //
  273. // Functional Description
  274. //
  275. //    For each window increment the counter.
  276. //
  277. // End ---------------------------------------------------------------------
  278.  
  279. // class BrowserFrame //
  280.  
  281. class BrowserFrame:public TMDIFrame
  282. {
  283. private:
  284.     PXI *engine;                /* Pointer to engine
  285.                            initialization object */
  286.     int error;                /* error flag */
  287.     WNDCLASS *MyClass;            /* Windows class */
  288. public:
  289.                         /* Browser frame constructor
  290.                         */
  291.     BrowserFrame(LPSTR ATitle);
  292.                         /* Create a child window */
  293.     virtual PTWindowsObject CreateChild();
  294.     ~BrowserFrame();            /* Close down all your
  295.                            children */
  296.                         /* Set up frame to so that
  297.                            you can have child
  298.                            windows */
  299.     void SetupWindow();
  300.                         /* If a file open command is
  301.                            recieved, open a new
  302.                            browser window */
  303.     virtual void CreateBrowser(RTMessage Msg) =
  304.         [CM_FIRST + CM_FILEOPEN];
  305.                         /* Count the number of child
  306.                            windows. */
  307.     int GetChildCount();
  308.     void MenuItemDisable(int item);        /* Disable a menu item */
  309.     void MenuItemEnable(int item);        /* Enable a menu item */
  310.                         /* Check your children.  This
  311.                            message is sent by the
  312.                            browser fram that is in
  313.                            the process of destroying
  314.                            itself. */
  315.     virtual void CheckChildren(RTMessage Msg) =
  316.         [WM_CHKCHILD];
  317.     virtual void GetWindowClass(WNDCLASS& AWndClass);
  318.                         /* Set the mouse cursor to
  319.                            hour glass type */
  320.     virtual void CursorWait(RTMessage Msg) =
  321.         [WM_SETWTCUR];
  322.                         /* Set the mouse cursor to
  323.                            normal type */
  324.     virtual void CursorNormal(RTMessage Msg) =
  325.         [WM_SETNMCUR];
  326. };
  327.  
  328. // Description -------------------------------------------------------------
  329. //
  330. //    This class allows construction of the MDI frame which will hold all
  331. //    the child windows.
  332. //
  333. // End ---------------------------------------------------------------------
  334.  
  335. #endif